var wxCharts = require('../../utils/wxcharts.js');
var historyChart = null;
let windowWidth = 320;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value: '',
    unit: '',
    title:'',
    prv: [],
    prvText:'',
    grade: '',
    categories: [],
    series: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const title = wx.getStorageSync('title');
    wx.setNavigationBarTitle({
      title: title
    });
    const value = wx.getStorageSync('value');
    const unit = wx.getStorageSync('unit');
    const grade = wx.getStorageSync('grade');
    const prvJson = wx.getStorageSync('prv');
    const prv = JSON.parse(prvJson);
    const categoriesJson = wx.getStorageSync('categories');
    const categories = JSON.parse(categoriesJson);
    const seriesJson = wx.getStorageSync('series');
    const seriesData = JSON.parse(seriesJson);
    let res = wx.getSystemInfoSync();
    windowWidth = res.windowWidth;
    let prvText = '';
    if (prv.length>0){
      prvText = prv.join("-");
    }
    this.setData({
      value,
      unit,
      grade,
      prvText,
      prv,
      title,
      categories,
      series: seriesData
    });
    if (categories.length == 0 || seriesData.length == 0) {
      return;
    }
    const series = [{
      name: title,
      data: seriesData
    }];
    historyChart = new wxCharts({
      canvasId: 'chartCanvas',
      type: 'line',
      categories,
      series,
      yAxis: {
        title,
        min: 0
      },
      width: windowWidth,
      height: 280,
      extra: {
        lineStyle: 'curve'
      }
    });
  },
})